Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@preact/signals
Advanced tools
Signals is a performant state management library with two primary goals:
Read the announcement post to learn more about which problems signals solves and how it came to be.
npm install @preact/signals
The Preact integration can be installed via:
npm install @preact/signals
It allows you to access signals as if they were native to Preact. Whenever you read a signal inside a component we'll automatically subscribe the component to that. When you update the signal we'll know that this component needs to be updated and will do that for you.
// The Preact adapter re-exports the core library
import { signal } from "@preact/signals";
const count = signal(0);
function CounterValue() {
// Whenever the `count` signal is updated, we'll
// re-render this component automatically for you
return <p>Value: {count.value}</p>;
}
If you need to instantiate new signals or create new side effects on signal changes inside your components, you can use the useSignal
, useComputed
and useSignalEffect
hooks.
import { useSignal, useComputed, useSignalEffect } from "@preact/signals";
function Counter() {
const count = useSignal(0);
const double = useComputed(() => count.value * 2);
useSignalEffect(() => {
console.log(`Value: ${count.value}, value x 2 = ${double.value}`);
});
return (
<button onClick={() => count.value++}>
Value: {count.value}, value x 2 = {double.value}
</button>
);
}
The Preact adapter ships with several optimizations it can apply out of the box to skip virtual-dom rendering entirely. If you pass a signal directly into JSX, it will bind directly to the DOM Text
node that is created and update that whenever the signal changes.
import { signal } from "@preact/signals";
const count = signal(0);
// Unoptimized: Will trigger the surrounding
// component to re-render
function Counter() {
return <p>Value: {count.value}</p>;
}
// Optimized: Will update the text node directly
function Counter() {
return <p>Value: {count}</p>;
}
To opt into this optimization, simply pass the signal directly instead of accessing the .value
property.
We can also pass signals directly as an attribute to an HTML element node.
import { signal } from "@preact/signals";
const inputValue = signal("foobar");
function Person() {
return <input value={inputValue} onInput={...} />;
}
This way we'll bypass checking the virtual-dom and update the DOM property directly.
MIT
, see the LICENSE file.
FAQs
Manage state with style in Preact
We found that @preact/signals demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.